package D12_19z.BU_XML_5;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) throws Exception{
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("src/Y2019/M12_/D12_19z/BU_XML_5/student.xml");
        Element root = read.getRootElement();
        ArrayList<Student> arr = new ArrayList<>();
        List<Element> student = root.elements("student");
        for (Element e : student) {
            Student s = new Student();
            s.setName(e.elementText("name"));
            s.setStuNo(e.attributeValue("stuNo"));
            s.setAge(Integer.parseInt(e.elementText("age")));
            s.setSex(e.elementText("sex"));
            s.setScore(Integer.parseInt(e.elementText("score")));
            arr.add(s);
        }
        for (Student student1 : arr) {
            System.out.println(student1);
        }
    }
}
